/*
 * Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contact: mosaic@fokus.fraunhofer.de
 */
package org.eclipse.mosaic.fed.sumo.traci.facades;

import org.eclipse.mosaic.fed.sumo.traci.TraciCommandException;
import org.eclipse.mosaic.fed.sumo.traci.TraciConnection;
import org.eclipse.mosaic.fed.sumo.traci.commands.*;
import org.eclipse.mosaic.rti.api.InternalFederateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.util.List;

public class TraciVehicleTypeFacade {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    private final TraciConnection traciConnection;

    private final VehicleTypeGetIds vehicleTypeGetIds;

    private final VehicleTypeCopy vehicleTypeCopy;

    private final VehicleTypeSetColor vehicleTypeSetColor;

    private final VehicleTypeSetHeight vehicleTypeSetHeight;

    private final VehicleTypeSetLength vehicleTypeSetLength;

    private final VehicleTypeSetWidth vehicleTypeSetWidth;

    private final VehicleTypeSetVehicleClass vehicleTypeSetVehicleClass;

    private final VehicleTypeSetShapeClass vehicleTypeSetShapeClass;

    public TraciVehicleTypeFacade(TraciConnection traciConnection) {
        this.traciConnection = traciConnection;

        this.vehicleTypeGetIds = traciConnection.getCommandRegister().getOrCreate(VehicleTypeGetIds.class);
        this.vehicleTypeCopy = traciConnection.getCommandRegister().getOrCreate(VehicleTypeCopy.class);
        this.vehicleTypeSetColor = traciConnection.getCommandRegister().getOrCreate(VehicleTypeSetColor.class);
        this.vehicleTypeSetHeight = traciConnection.getCommandRegister().getOrCreate(VehicleTypeSetHeight.class);
        this.vehicleTypeSetLength = traciConnection.getCommandRegister().getOrCreate(VehicleTypeSetLength.class);
        this.vehicleTypeSetWidth = traciConnection.getCommandRegister().getOrCreate(VehicleTypeSetWidth.class);
        this.vehicleTypeSetVehicleClass = traciConnection.getCommandRegister().getOrCreate(VehicleTypeSetVehicleClass.class);
        this.vehicleTypeSetShapeClass = traciConnection.getCommandRegister().getOrCreate(VehicleTypeSetShapeClass.class);
    }

    public List<String> getVehicleTypeIds() throws InternalFederateException {
        try {
            return vehicleTypeGetIds.execute(traciConnection);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not request all vehicle type ids", e);
        }
    }

    public void copyVehicleType(String originTypeId, String typeId) throws InternalFederateException {
        try {
            vehicleTypeCopy.execute(traciConnection, originTypeId, typeId);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not copy vehicle type from " + originTypeId, e);
        }
    }

    public void setVehicleSetColor(String typeId, Color color) throws InternalFederateException {
        try {
            vehicleTypeSetColor.execute(traciConnection, typeId, color);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not set color of vehicle type ", e);
        }
    }

    public void setVehicleTypeHeight(String typeId, double height) throws InternalFederateException {
        try {
            vehicleTypeSetHeight.execute(traciConnection, typeId, height);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not set height of vehicle type ", e);
        }
    }

    public void setVehicleTypeLength(String typeId, double length) throws InternalFederateException {
        try {
            vehicleTypeSetLength.execute(traciConnection, typeId, length);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not set length of vehicle type ", e);
        }
    }

    public void setVehicleTypeWidth(String typeId, double width) throws InternalFederateException {
        try {
            vehicleTypeSetWidth.execute(traciConnection, typeId, width);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not set width of vehicle type ", e);
        }
    }

    public void setVehicleTypeVehicleClass(String typeId, String vehicleClass) throws InternalFederateException {
        try {
            vehicleTypeSetVehicleClass.execute(traciConnection, typeId, vehicleClass);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not set vehicle class of vehicle type ", e);
        }
    }

    public void setVehicleTypeShapeClass(String typeId, String shapeClass) throws InternalFederateException {
        try {
            vehicleTypeSetShapeClass.execute(traciConnection, typeId, shapeClass);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not set shape class of vehicle type ", e);
        }
    }
}
